package com.invite.me.beans.presenter;

import android.util.Log;


import com.google.gson.Gson;
import com.invite.me.api.UrlConstants;
import com.invite.me.beans.fabean.InviteRecordDetailByXqFaBean;
import com.invite.me.beans.fabean.InviteRecordTyfuFaBean;
import com.invite.me.beans.res.InviteRecordDetailByXqShouBean;
import com.invite.me.beans.res.InviteRecordTyfuShouBean;
import com.invite.me.ui.yaoyue.InviteRecordDetailByyActivity;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.invite.me.wlqq.RxJavaDataImpl;

import java.io.IOException;
import java.util.HashMap;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class InviteRecordDetailByPresenter implements Contract.BasePresenter{

    InviteRecordDetailByyActivity splashActivity;

    public InviteRecordDetailByPresenter(InviteRecordDetailByyActivity signInActivity) {
        this.splashActivity = signInActivity;
        splashActivity.setPresenter(this);
    }
    @Override
    public void start() {

    }

    //查看详情页
    public void ChakanXiangqing(String aid ) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        InviteRecordDetailByXqFaBean logeInDataBean = new InviteRecordDetailByXqFaBean();
        logeInDataBean.setId(aid);




        Gson gson = new Gson();
        String phoneNumber = gson.toJson(logeInDataBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);

        RxJavaDataImpl.postData(UrlConstants.CKYYJLXQ, hashMap, requestBody, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        InviteRecordDetailByXqShouBean gankInfo = gson.fromJson(str, InviteRecordDetailByXqShouBean.class);
                        splashActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                splashActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                splashActivity.onComplete();
            }
        });
    }

    public void ZhiFuBaoZhiFu(String aid ) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        InviteRecordDetailByXqFaBean logeInDataBean = new InviteRecordDetailByXqFaBean();
        logeInDataBean.setId(aid);
        Gson gson = new Gson();
        String phoneNumber = gson.toJson(logeInDataBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);

        RxJavaDataImpl.postData(UrlConstants.ZFBZF, hashMap, requestBody, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        InviteRecordDetailByXqShouBean gankInfo = gson.fromJson(str, InviteRecordDetailByXqShouBean.class);
                        splashActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                splashActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                splashActivity.onComplete();
            }
        });
    }

//同意邀约
    public void Tongyiyaoyue(String id ,String zijiid) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        InviteRecordTyfuFaBean inviteRecordTyfuFaBean=new InviteRecordTyfuFaBean();
        inviteRecordTyfuFaBean.setUserIdb(zijiid);
        inviteRecordTyfuFaBean.setId(id);
        Gson gson = new Gson();
        String phoneNumber = gson.toJson(inviteRecordTyfuFaBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);

        RxJavaDataImpl.postData(UrlConstants.TONGYIFUYUE, hashMap, requestBody, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        InviteRecordTyfuShouBean gankInfo = gson.fromJson(str, InviteRecordTyfuShouBean.class);
                        splashActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                splashActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                splashActivity.onComplete();
            }
        });
    }

}
